import axios from 'axios';

const API_URL = 'http://localhost:9000'; // 替换为你的后端地址

const axiosInstance = axios.create({
    baseURL: API_URL,
    withCredentials: true // 确保请求带上Cookie
});

export class UserService {
    static async login(data: { username: string; password: string; }) {
        return axiosInstance.post('/user/login', data);
    }

    static async register(data: { username: string; password: string; phone: string; email: string; tenant: string; gender: string; }) {
        return axiosInstance.post('/user/register', data);
    }

    static async updateUser(data: { avatar: string; nickname: string; username: string; phone: string; email: string; department: string; role: string; gender: string; tags: never[]; }) {
        return axiosInstance.put('/user/update', data);
    }

    static async deleteUser(id: any) {
        return axiosInstance.delete('/user/delete', { params: { id } });
    }

    static async getProfile() {
        return axiosInstance.get('/user/profile');
    }

    static async changePassword(data: { oldPassword: string; newPassword: string; confirmPassword: string; }) {
        return axiosInstance.post('/user/changePassword', data);
    }

    static async logout() {
        return axiosInstance.post('/user/logout');
    }
}
